<?php
error_reporting(E_ALL);
//-------------parser----------------------------------------------------

$request_url = $_SERVER['REQUEST_URI'];
$arr 		 = explode("/",$request_url);

$ignore = false;

//process banner
$banner = array();
$bannerUrl   = explode("?",$request_url);
array_push($banner, $bannerUrl[count($bannerUrl)-1]);
foreach ($banner as $banner_url)
{
    if (strstr($banner_url,"utm_source=IO_Channel2&utm_medium=Banner&utm_campaign=Solvay"))
    {
        $ignore = true;
    }
}

//process google adwords
if (strpos($request_url,"?gclid="))
{
    $ignore = true;
}

//get the args for dispatch
$arrArgs	= array();
$j=0;
for($i=3;$i<count($arr);$i++) {
	$arrArgs[] = $arr[$i];
}
extract($arrArgs,EXTR_SKIP);

$_SERVER['PHP_SELF'] = $request_url;


//--------------include framework_config file--------------------------------------------------------------
include ("library/config/fw_config.php");

//-------------------------route controller----------------------------------------------------------------
$controller = ($arr[1]!="")? ucfirst($arr[1])		: ucfirst(DEFAULT_CONTROLLER);
$action     = ($arr[2]!="")? strtolower($arr[2])	: strtolower(DEFAULT_CONTROLLER_ACTION);

/*if ( !isset($_SESSION["SOLVAY_MBA"]) &&  $controller != 'Admin' && $controller != 'Cront' && $controller != 'Login' )
{
	session_register("SOLVAY_MBA");
	$_SESSION["SOLVAY_MBA"] = "SOLVAY_MBA";
	redirect(APPLICATION_URL . "mba");
}*/
if ($ignore)
{
    $controller = ucfirst(DEFAULT_CONTROLLER);
    $action = strtolower(DEFAULT_CONTROLLER_ACTION);
}

$pos = strpos($action,"?");
if($pos)
{
	$action = substr($action,0,$pos);
}
$pos = strpos($controller,"?");
if($pos)
{
	$controller = substr($controller,0,$pos);
}

$account = false;
if (isset($_SESSION["account"]))
{
	$account = $_SESSION["account"];
}

if ($account===false && $controller=="Admin"){
	$controller = "Login";
	$action = "index";
}

//register var modules, action and args
DRX::register("controller", strtolower($controller));
DRX::register("action", $action);
DRX::register("args", $args);
$smarty->assign("action_function", $action);


if(isset($page) && $page>0) DRX::register("page", $page);

//--------------include language file----------------------------------------------------------------------
//if ($current_lang != '') {
//	include_once (APPLICATION_DIR."/application/language/".$current_lang."/common.php");
//}

$ControllerName = $controller."Controller";
$ActionName 	= $action."Action";

if(file_exists("application/controller/".$ControllerName.".php")) 
{
	if (class_exists($ControllerName)) 
	{
		$objHandlerController = new $ControllerName();
		if(method_exists($objHandlerController,$ActionName)) 
		{
			$objHandlerController->$ActionName();
		}
		else 
		{
			die("Cannot find method <strong>".$ActionName."</strong> in ".$ControllerName." class to execute");
		}
	}
	else 
	{
		die("Cannot find className <strong>".$ControllerName."</strong> in ".$ControllerName.".php modules to execute");
	}
}
else 
{
	die("Cannot find controller modules $ControllerName to execute");
}
?>	